import { constantRoutes } from '@/router'

const state = {
    addRoutes: [],
    routes: [],
    token: "", //token
    routeID: [], //路由权限ID
    user: {
        id: "",
        account: "",
        roleType: "",
    },
}

const mutations = {
    USER_INFORMATION: (state, login) => {
        state.addRoutes = login;
        state.routes = state.addRoutes.concat(constantRoutes)
        sessionStorage.setItem("routes", JSON.stringify(state.routes))
        sessionStorage.setItem("addRoutes", JSON.stringify(state.addRoutes))
    },
    USER_TOKEN: (state, token) => {
        state.token = token;
        sessionStorage.setItem("token", JSON.stringify(state.token))
    },
    USER_DEANID: (state, deanId) => {
        state.deanId = deanId;
        sessionStorage.setItem("deanId", JSON.stringify(state.deanId))
    },
    USER_ROUTEID: (state, id) => {
        state.routeID = id;
        sessionStorage.setItem("routeID", JSON.stringify(state.routeID))
    },
    USER_INFO: (state, user) => {
        state.user.id = user.id;
        state.user.account = user.account;
        state.user.roleType = user.roleType
        sessionStorage.setItem("userInfo", JSON.stringify(state.user))
    }
}

const actions = {
    user_information: ({ commit }, login) => {
        commit("USER_INFORMATION", login)
    },
    user_token: ({ commit }, token) => {
        commit("USER_TOKEN", token)
    },
    user_deanId: ({ commit }, deanId) => {
        commit("USER_DEANID", deanId)
    },
    user_routeid: ({ commit }, id) => {
        commit("USER_ROUTEID", id)
    },
    user_info: ({ commit }, user) => {
        commit("USER_INFO", user)
    }
}



export default {
    namespaced: true,
    state,
    mutations,
    actions
}